﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.OracleClient;
using System.Text;
using ReflectionStudio.Core.Events;
using INTEX.DataBase.Tools;
using INTEX.DataBase;
using WPFExcelReport.Helpers;
namespace WPFExcelReport
{

    public class JLTVR04DOCData : BaseFunction
    {

        SETINTEXDB INTEXDB = new SETINTEXDB();
        INTEXDBC INTEXDBC;
        public JLTVR04DOCData()
            : base()
        {

        }
        public JLTVR04DOCData(OracleConnection _myConnection, IntexReptServBLClient _proxy, string userID = "        ")
            : base(_myConnection, _proxy, userID)
        {
            INTEXDBC = new INTEXDBC(OracleDB, proxy);
        }
        public JLTVR04DOCData(Dictionary<string, object> DicGlobalPara)
            : base(DicGlobalPara)
        {
        }

        public DataSet GetData(DataRow dwInput)
        {
            DataSet SReturn = new DataSet();
            DataSet SResult = new DataSet();
            DataSet STemp = new DataSet();
            DataRow dwTemp;
            DataRow dwVK04 = null;
            try
            {
                dwTemp = INTEXDB.VKKOPF.NewRow();
                dwTemp["VKKMANDANT"] = dwInput["VRPMANDANT"];
                dwTemp["VKKAUFKRS"] = dwInput["VRPAUFKRS"];
                dwTemp["VKKAUFLFD"] = dwInput["VRPAUFLFD"];
                SResult = INTEXDBC.QueryVKKOPF(dwTemp, 1);
                if (SResult.Tables.Count == 0)
                    return SReturn;
                foreach (DataRow row in SResult.Tables[0].Rows)
                {
                    dwVK04 = row;
                }
                if (dwVK04 == null)
                    return SReturn;
                SReturn.Merge(SResult);
                dwTemp = INTEXDB.VRKOPF.NewRow();
                dwTemp["VRKMANDANT"] = dwInput["VRPMANDANT"];
                dwTemp["VRKRENR"] = dwInput["VRPRENR"];
                SResult = INTEXDBC.QueryVRKOPF(dwTemp, 3);
                SReturn.Merge(SResult);
                dwTemp = INTEXDB.VRPOS.NewRow();
                dwTemp["VRPMANDANT"] = dwInput["VRPMANDANT"];
                dwTemp["VRPAUFKRS"] = dwInput["VRPAUFKRS"];
                dwTemp["VRPAUFLFD"] = dwInput["VRPAUFLFD"];
                dwTemp["VRPRENR"] = dwInput["VRPRENR"];
                SResult = INTEXDBC.QueryVRPOS(dwTemp, 2);
                SReturn.Merge(SResult);
                dwTemp = INTEXDB.ZABED.NewRow();
                dwTemp["ZABMANDANT"] = dwVK04["VKKMANDANT"];
                dwTemp["ZABNR"] = dwVK04["VKKZAHLBED"];
                SResult = INTEXDBC.QueryZABED(dwTemp, 1);
                dwTemp = INTEXDB.TXTIND.NewRow();
                dwTemp["TXTIMANDANT"] = dwVK04["VKKMANDANT"];
                dwTemp["TXTITXTART"] = "ZAB";
                dwTemp["TXTISIND"] = Helper.Left(dwVK04["VKKZAHLBED"].ToString() + "V                                                                                       ", 60);
                SResult = INTEXDBC.QueryTXTKON(dwTemp, 1);
                dwTemp = setTXT.TXTKON.NewRow();
                SResult = Helper.ConvertTXT(SResult.Tables["TXTKON"], dwTemp);
                SReturn.Merge(SResult);
                dwTemp = INTEXDB.TXTIND.NewRow();
                dwTemp["TXTIMANDANT"] = dwVK04["VKKMANDANT"];
                dwTemp["TXTITXTART"] = "ZAB";
                dwTemp["TXTISIND"] = Helper.Left(dwVK04["VKKZAHLBED"].ToString() + "E                                                                                       ", 60);
                SResult = INTEXDBC.QueryTXTKON(dwTemp, 1);
                dwTemp = setTXT.TXTKON.NewRow();
                SResult = Helper.ConvertTXT(SResult.Tables["TXTKON"], dwTemp);
                SReturn.Merge(SResult);

                dwTemp = INTEXDB.VRPOS.NewRow();
                dwTemp["VRPMANDANT"] = dwInput["VRPMANDANT"];
                dwTemp["VRPAUFKRS"] = dwInput["VRPAUFKRS"];
                dwTemp["VRPAUFLFD"] = dwInput["VRPAUFLFD"];
                dwTemp["VRPRENR"] = dwInput["VRPRENR"];
                SResult = INTEXDBC.QueryVVTLIEF(dwTemp, 4);
                SReturn.Merge(SResult);
                dwTemp = INTEXDB.VRPOS.NewRow();
                dwTemp["VRPMANDANT"] = dwInput["VRPMANDANT"];
                dwTemp["VRPAUFKRS"] = dwInput["VRPAUFKRS"];
                dwTemp["VRPAUFPOS"] = dwInput["VRPAUFPOS"];
                dwTemp["VRPRENR"] = dwInput["VRPRENR"];
                SResult = INTEXDBC.QueryVVLIEF(dwTemp, 2);
                SReturn.Merge(SResult);
                dwTemp = INTEXDB.VKPOS.NewRow();
                dwTemp["VKPMANDANT"] = dwInput["VRPMANDANT"];
                dwTemp["VKPAUFKRS"] = dwInput["VRPAUFKRS"];
                dwTemp["VKPAUFLFD"] = dwInput["VRPAUFLFD"];
                SResult = INTEXDBC.QueryVKPOS(dwTemp, 3);
                SReturn.Merge(SResult);
                DataRow dwVKP = SResult.Tables[0].Rows[0];
                SResult = INTEXDBC.QueryVAART(dwVKP, 3);
                SReturn.Merge(SResult);
                SResult = INTEXDBC.QueryVAFARBEN(dwVKP, 3);
                SReturn.Merge(SResult);
                SResult = INTEXDBC.QueryVAKDBEZ(dwVKP, 3);
                SReturn.Merge(SResult);          
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return SReturn;
        }
        public DataSet BuildData(DataRow dwInput)
        {
            DataSet SReturn = new DataSet();
            DataSet SResult = new DataSet();
            DataSet STemp = new DataSet();
            DataRow dwTemp;
            try
            {
                dwTemp = INTEXDB.VRPOS.NewRow();
                dwTemp["VRPMANDANT"] = dwInput["VRPMANDANT"];
                dwTemp["VRPAUFKRS"] = dwInput["VRPAUFKRS"];
                dwTemp["VRPAUFLFD"] = dwInput["VRPAUFLFD"];
                SResult = INTEXDBC.QueryVRKOPF(dwTemp, 2);
                SReturn.Merge(SResult);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return SReturn;
        }
    }
}